# Contributor: Dennis Przytarski <dennis@przytarski.com>
# Maintainer: ScrumpyJack <scrumypjack@st.ilet.to>
pkgname=rng-tools
pkgver=6.10
pkgrel=2
pkgdesc="A random number generator daemon"
url="https://github.com/nhorman/rng-tools"
arch="all"
license="GPL-2.0-or-later"
makedepends="argp-standalone autoconf automake linux-headers libtool
	sysfsutils-dev
	openssl-dev
	librtlsdr-dev
	"
subpackages="$pkgname-doc $pkgname-openrc"
source="rng-tools-$pkgver.tar.gz::https://github.com/nhorman/rng-tools/archive/v$pkgver.tar.gz
	fix-textrels-on-PIC-x86.patch
	fix-encrypt-name-clash.patch
	stack.patch
	rngd.confd
	rngd.initd
	"

# power DARN support requires libgcrypt
case "$CARCH" in
	ppc64le) makedepends="$makedepends libgcrypt-dev";;
	*) _flags="--without-libgcrypt";;
esac

prepare() {
	default_prepare
	./autogen.sh
}

build() {
	export LIBS="-largp"

	# NOTE: nistbeacon depends on libxml2 and libcurl, so it would
	# significantly increase rng-tools' total size.
	# Likewise for libgcrypt.
	./configure \
		--prefix=/usr \
		--libexecdir=/usr/lib/rng-tools \
		--sysconfdir=/etc \
		--disable-silent-rules \
		--without-nistbeacon \
		--without-pkcs11 \
		$_flags
	make
}

package() {
	make DESTDIR="$pkgdir" install

	install -m 644 -D "$srcdir"/rngd.confd "$pkgdir"/etc/conf.d/rngd
	install -m 755 -D "$srcdir"/rngd.initd "$pkgdir"/etc/init.d/rngd
}

sha512sums="b72d8918f709989ebc70cb9ea9c8b3dabf53041b24bc3f3a6de1bea318861dfd6c1a6110bd750041dc4819406db4a2b28f5137af5f5d5f2beb666f607913b389  rng-tools-6.10.tar.gz
241b56146ec8e55572711b7aa36fa2afbe7a9527d25f03098f35f4c52a9049933d9bc2a82b0e2e0dbc836409d7f650f3a88ef546d6c5a687f7be8fbe4a013b7e  fix-textrels-on-PIC-x86.patch
c65d177b20948f88341b22149325011fca93da1137cb176f642ae1944ffc2110141e123518fcc1329346a21c57a51a6cf22f8f06f7d10337a7b1a50c243e97cf  fix-encrypt-name-clash.patch
bd0a6caf5a44796c7efdacfa19fb725c2ea61951dec039607471382597fdc919d28640e159dd58db8df4d7f36e12318f86b078666fad1929816031061b13f677  stack.patch
363b5aa431a0da37fc9eb8c93cffed0b75f43064530318fb41c774acd8aab8a1e109cf6c294b77fa6b8f97aa355b2849f56e83d8b06bcd9e0e9f3aa4f3ba49ac  rngd.confd
86a6a7446eda64c075e468bc304008314b710629e06146582c5ce3fcc307a6b4baf5f8e8a47b72f1bab0bb608d76f953f2712cddd35809abcb02b8320c682535  rngd.initd"
